<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Controller.php 2010-09-07 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Like_Widget_SuggestController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    if (!Engine_Api::_()->getDbTable('modules', 'core')->isModuleEnabled('like')){
      $this->setNoRender();
      return ;
    }
    
    if (!Engine_Api::_()->getApi('settings', 'core')->getSetting('like.profile.enabled', 1)){
      $this->setNoRender();
      return ;
    }
    
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    
    if (!$viewer->getIdentity()){
      $this->setNoRender();
      return ;
    }
    
  	$like_club = Engine_Api::_()->like()->getRandomLikeClub();
    if (!$like_club){
      $this->setNoRender();
      return ;
    }
    
  	$this->view->subject = $subject = $like_club->getSubject();
  	$this->view->isViewerLike = Engine_Api::_()->like()->isLike($subject);
  	
 		if (!$like_club || !$subject){
 			$this->setNoRender();
 		}
 		
 		$this->view->likes = $like_club->getLikes(array('ipp' => 6));
 		$params = array('count' => true, 'club_id' => $like_club->getIdentity());
 		$this->view->friendsCount = (int)Engine_Api::_()->like()->getMutualFriendsAmongLikes($params);
  }
}